package com.aerozhonghuan.logisticsmall.framework.hybrid.actions;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.aerozhonghuan.logisticsmall.framework.hybrid.NewWebviewActivity;
import com.aerozhonghuan.logisticsmall.framework.hybrid.NewWebviewFragment;
import com.aerozhonghuan.logisticsmall.framework.hybrid.SimpleActionHandler;
import com.aerozhonghuan.logisticsmall.framework.hybrid.bean.JsMobileAgentConstants;
import com.aerozhonghuan.hybrid.XJsCallback;

import org.json.JSONObject;

/**
 * 描述
 * 作者 Zhang Yonghui
 * 创建日期 2019/1/21
 */
public class OpenNewWindowActionHandler extends SimpleActionHandler {
    private static final String KEY_URL = "url";
    private static final String KEY_TITLE = "title";
    private static final String KEY_TAG = "tag";

    public OpenNewWindowActionHandler(NewWebviewFragment fragment) {
        super(JsMobileAgentConstants.FLAG_OPENNEWWINDOW, fragment);
    }

    @Override
    public void handleAction(@NonNull String action, @Nullable JSONObject params, @Nullable XJsCallback callBack) {
        if (params == null) {
            return;
        }
        String url = params.optString(KEY_URL);
        String title = params.optString(KEY_TITLE);
        String tag = params.optString(KEY_TAG);
        getActivity().startActivity(new Intent(getActivity(), NewWebviewActivity.class).putExtra("url", url).putExtra("title", title).putExtra(KEY_TAG,tag));

    }
}
